/////////////////////////////////////////////////////////////////////////////
// Name:        epub_kewords.cpp
// Purpose:     Keyword provider for epub info
// Author:      Julian Smart
// Modified by:
// Created:     2008-11-18
// RCS-ID:      $Id$
// Copyright:   (c) Julian Smart
// Licence:     New BSD License
/////////////////////////////////////////////////////////////////////////////

#include "wx/wx.h"

#include "epubutils/epub_keywords.h"

/*!
 * Special keyword provider for ePub basic info
 */

/// Override to do subtitutions.
bool ebEpubKeywordProvider::PerformSubstitutions(wxString& value) const
{
    wxArrayString arr = EnumerateKeywords();

    size_t i;
    for (i = 0; i < arr.GetCount(); i++)
    {
        wxString kvalue = GetKeywordValue(arr[i]);
        value.Replace(arr[i], kvalue);
    }

    return true;
}

/// Override to list the available keywords. By default, uses the built-in keyword table.
wxArrayString ebEpubKeywordProvider::EnumerateKeywords() const
{
    wxArrayString arr;
    arr.Add(wxT("%TITLE%"));
    arr.Add(wxT("%ID%"));
    arr.Add(wxT("%LANGUAGE%"));
    arr.Add(wxT("%AUTHOR%"));
    arr.Add(wxT("%CONTRIBUTORS%"));
    arr.Add(wxT("%PUBLISHER%"));
    arr.Add(wxT("%URL%"));
    arr.Add(wxT("%SUBJECT%"));
    arr.Add(wxT("%DESCRIPTION%"));
    arr.Add(wxT("%DATE%"));
    arr.Add(wxT("%RIGHTS%"));
    arr.Add(wxT("%COVERAGE%"));
    arr.Add(wxT("%TYPE%"));
    arr.Add(wxT("%FORMAT%"));
    arr.Add(wxT("%SOURCE%"));
    arr.Add(wxT("%RELATION%"));

    return arr;
}

/// Override to get the value for a keyword.
wxString ebEpubKeywordProvider::GetKeywordValue(const wxString& keyword) const
{
    wxASSERT(m_info != NULL);
    if (!m_info)
        return wxEmptyString;

    if (keyword == wxT("%TITLE%"))
        return m_info->GetTitle();
    else if (keyword == wxT("%AUTHOR%"))
        return m_info->GetAuthor();
    else if (keyword == wxT("%ID%"))
        return m_info->GetId();
    else if (keyword == wxT("%LANGUAGE%"))
        return m_info->GetLanguage();
    else if (keyword == wxT("%CONTRIBUTORS%"))
        return m_info->GetContributors();
    else if (keyword == wxT("%PUBLISHER%"))
        return m_info->GetPublisher();
    else if (keyword == wxT("%URL%"))
        return m_info->GetUrl();
    else if (keyword == wxT("%SUBJECT%"))
        return m_info->GetSubject();
    else if (keyword == wxT("%DESCRIPTION%"))
        return m_info->GetDescription();
    else if (keyword == wxT("%DATE%"))
        return m_info->GetDate();
    else if (keyword == wxT("%RIGHTS%"))
        return m_info->GetRights();
    else if (keyword == wxT("%COVERAGE%"))
        return m_info->GetCoverage();
    else if (keyword == wxT("%TYPE%"))
        return m_info->GetType();
    else if (keyword == wxT("%FORMAT%"))
        return m_info->GetFormat();
    else if (keyword == wxT("%SOURCE%"))
        return m_info->GetSource();
    else if (keyword == wxT("%RELATION%"))
        return m_info->GetRelation();
    else
    {
        wxASSERT(false);
        return wxEmptyString;
    }
}
